<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>后台 订单列表</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <!-- 工具 -->
    <script src="js/HttpUtil.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            selectOrders();
        });
        // <td>${s.state==4?`<button type="button" class="btn btn-danger btn-sm"
        //                         onclick="sendOrder(${s.id})">发货</button>`:null}</td>

        function selectOrders(){
            //ajax 请求后台
            var url="adminOrders/select";
            url=appendHost(url);
            $.ajax({
                url:url,
                method:"post",
                success:function (resp2) {
                    handleResp(resp2,function (res) {
                        console.log("showGoodsType222");
                        console.log(res);
                        var html = res.map(function (s) {
                            var template =
                                `<tr class="tr_head">
                                <td>${s.id}</td>
                                <td>${s.userId}</td>
                                <td>${s.money}</td>
                                <td>${s.orderNum}</td>
                                <td>${s.state}</td>
                                <td>${s.time}</td>
                                <td>${s.addressId}</td>
                                <td>${s.state==4?`<button type="button" class="btn btn-danger btn-sm"
                                onclick="sendOrder(${s.id})">发货</button>`:""}</td>

                                </tr>`;
                            // if (s.state==4){<td id="delivery"></td>
                            //     $("#delivery").html(`<button type="button" class="btn btn-danger btn-sm"
                            //     onclick="sendOrder(${s.id})">发货</button>`)
                            // }
                            return template
                        }).join("");
                        $("#tb_list").html(html);
                    });
                },
                error:function(XMLHttpRequest,textStatus,errorThrown){
                    alert("失败"+XMLHttpRequest.status+":"+textStatus+":"+errorThrown);
                }
            });
        }
        function sendOrder(id){
            if (confirm("确认要发货吗?")) {
                let url = "adminOrders/updateById";
                let params = {id:id};
                console.log(params);
                httpGet(url, params, function () {
                    selectOrders();
                });
            }
        };
        // function selectOrders() {
        //     let url="";
        //     let params;
        //     httpPost()
        // }
        //请求商品信息

    </script>
</head>
<body>
<div class="row" style="width:98%;margin-left: 1%;margin-top: 5px;">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                订单列表
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
                        <div class="form-group form-inline">
                            <span>用户姓名</span>
                            <input type="text" name="username" class="form-control">
                        </div>
                    </div>
                    <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
                        <div class="form-group form-inline">
                            <span>订单状态</span>
                            <select name="orderStatus" class="form-control">
                                <option value=" ">----------</option>
                                <option value="0">未支付</option>
                                <option value="1">支付失败</option>
                                <option value="2">已支付,待发货</option>
                                <option value="3">已发货,待收货</option>
                                <option value="4">完成订单</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                        <button type="button" class="btn btn-primary" id="search"><span class="glyphicon glyphicon-search"></span></button>
                    </div>
                </div>

                <table id="tb" class="table table-striped table-hover table-bordered table-condensed">
                    <tr>
                        <td>订单编号</td>
                        <td>所属用户</td>
                        <td>总金额</td>
                        <td>数量</td>
                        <td>订单状态</td>
                        <td>创建时间</td>
                        <td>订单地址id</td>
                        <td>操作</td>
                    </tr>
                    <tbody id="tb_list" class="table table-striped table-hover table-bordered">

                    </tbody>
<!--&lt;!&ndash;                    <c:forEach items="${orderList}" var="order" varStatus="i">&ndash;&gt;-->
<!--                        <tr>-->
<!--                            <td>${i.count}</td>-->
<!--                            <td>${order.o_id}</td>-->
<!--                            <td>${order.o_count}</td>-->
<!--&lt;!&ndash;                            <td>&ndash;&gt;-->
<!--&lt;!&ndash;                                <c:if test="${order.o_state eq 1}">&ndash;&gt;-->
<!--&lt;!&ndash;                                    未支付&ndash;&gt;-->
<!--&lt;!&ndash;                                </c:if>&ndash;&gt;-->
<!--&lt;!&ndash;                                <c:if test="${order.o_state eq 2}">&ndash;&gt;-->
<!--&lt;!&ndash;                                    已支付,待发货&ndash;&gt;-->
<!--&lt;!&ndash;                                </c:if>&ndash;&gt;-->
<!--&lt;!&ndash;                                <c:if test="${order.o_state eq 3}">&ndash;&gt;-->
<!--&lt;!&ndash;                                    已发货,待收货&ndash;&gt;-->
<!--&lt;!&ndash;                                </c:if>&ndash;&gt;-->
<!--&lt;!&ndash;                                <c:if test="${order.o_state eq 4}">&ndash;&gt;-->
<!--&lt;!&ndash;                                    订单完成&ndash;&gt;-->
<!--&lt;!&ndash;                                </c:if>&ndash;&gt;-->
<!--&lt;!&ndash;                                <c:if test="${order.o_state eq 5}">&ndash;&gt;-->
<!--&lt;!&ndash;                                    评价&ndash;&gt;-->
<!--&lt;!&ndash;                                </c:if>&ndash;&gt;-->
<!--&lt;!&ndash;                            </td>&ndash;&gt;-->
<!--                            <td>${order.o_time}</td>-->
<!--                            <td>${map.get(order.u_id)}</td>-->
<!--                            <td>-->
<!--&lt;!&ndash;                                <c:if test="${order.o_state eq 2}">&ndash;&gt;-->
<!--                                    <button type="button" class="btn btn-danger btn-sm" onclick="sendOrder('${order.o_id}')">发货</button>-->
<!--&lt;!&ndash;                                </c:if>&ndash;&gt;-->
<!--                            </td>-->
<!--                        </tr>-->
<!--&lt;!&ndash;                    </c:forEach>&ndash;&gt;-->

                </table>
            </div>
        </div>
    </div>
</div>
</body>
</html>